<?php

namespace App\Http\Services\User;

use App\Http\Services\BaseService;
use App\Models\Member;
use App\Models\MemberRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Hash;

class UserService extends BaseService {

    public static function register(Request $request)
    {
        $data = $request->all();


        $user =  User::query()->create([
            'name' => $data['name'] ?? null,
            'mobile' => $data['mobile'] ?? null,
            'email' => $data['email'] ?? null,
            'password' => Hash::make($data['password']),
        ]);

        $member = Member::saveEntity([
            'user_id' => $user->id,
            'nick_name' => $data['name'] ?? 'user_' . uniqid(),
            'mobile' => $data['mobile'] ?? null,
        ]);

        MemberRequest::saveEntity([
            'member_id' => $member->id,
        ]);

        return $user;
    }

}